import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import monacoEditorPlugin from 'vite-plugin-monaco-editor';
import path from 'path';

export default defineConfig({
    plugins: [
        vue({
            template: {
                compilerOptions: {
                    compatConfig: {
                        MODE: 2
                    }
                }
            }
        }),
        //NOTE: 这里要使用.default才能正常使用，具体见console.log('monacoEditorPlugin', monacoEditorPlugin);
        (monacoEditorPlugin as any).default({
            // languageWorkers: ['editorWorkerService', 'typescript', 'json'],
            // globalAPI: true,
            // // 新增：修复文件路径处理问题
            // publicPath: '/monaco-editor/'
        }),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    css: {
        preprocessorOptions: {
            scss: {
                // api: 'modern', // 明确指定使用现代 API
                additionalData: `@use "@/styles/variables.scss";`,
            }
        }
    },
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'),
        },
    },
    optimizeDeps: {
        exclude: ['monaco-editor', '@monaco-editor/loader']  // 防止 Vite 错误处理 Monaco 依赖
    }
});
